package ar.com.sgsvm.dao;


import android.database.sqlite.SQLiteDatabase;
import android.os.Environment;
import ar.com.sgsvm.dao.sqlite.ArticuloSqliteDao;
import ar.com.sgsvm.dao.sqlite.ClienteSqliteDao;
import ar.com.sgsvm.dao.sqlite.FacturaSqliteDao;
import ar.com.sgsvm.dao.sqlite.LineaFacturaSqliteDao;
import ar.com.sgsvm.dao.sqlite.LocalidadSqliteDao;
import ar.com.sgsvm.dao.sqlite.PrecioSqliteDao;
import ar.com.sgsvm.dao.sqlite.ProvinciaSqliteDao;
import ar.com.sgsvm.dao.sqlite.TipoArticuloSqliteDao;
import ar.com.sgsvm.dao.sqlite.TipoUsuarioSqliteDao;
import ar.com.sgsvm.dao.sqlite.UsuarioSqliteDao;

public class SqliteDaoFactory extends DaoFactory{

	private SQLiteDatabase mSqLiteDatabase;
	
	@Override
	public SQLiteDatabase open() throws Exception {
		String path = Environment.getExternalStorageDirectory().getAbsolutePath().concat("/sgsvm");
		if(mSqLiteDatabase == null || !mSqLiteDatabase.isOpen()){
			mSqLiteDatabase = SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READWRITE|SQLiteDatabase.NO_LOCALIZED_COLLATORS);
		}
		return mSqLiteDatabase;
	}

	@Override
	public void close() throws Exception {
		mSqLiteDatabase.close();
	}

	@Override
	public void reset() throws Exception {
		mSqLiteDatabase = null;
	}

	@Override
	public void beginTransaction() throws Exception {
		mSqLiteDatabase.beginTransaction();
	}

	@Override
	public void commit() throws Exception {
		mSqLiteDatabase.setTransactionSuccessful();
		mSqLiteDatabase.endTransaction();
	}

	@Override
	public void rollback() throws Exception {
		mSqLiteDatabase.endTransaction();
	}

	@Override
	public void backup() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void restore() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public IClienteDao getClienteDao() {
		return new ClienteSqliteDao();
	}

	@Override
	public IArticuloDao getArticuloDao() {
		return new ArticuloSqliteDao();
	}

	@Override
	public IFacturaDao getFacturaDao() {
		return new FacturaSqliteDao();
	}

	@Override
	public ILineaFacturaDao getLineaFacturaDao() {
		return new LineaFacturaSqliteDao();
	}

	@Override
	public ILocalidadDao getLocalidadDao() {
		return new LocalidadSqliteDao();
	}

	@Override
	public IPrecioDao getPrecioDao() {
		return new PrecioSqliteDao();
	}

	@Override
	public IProvinciaDao getProvinciaDao() {
		return new ProvinciaSqliteDao();
	}

	@Override
	public ITipoArticuloDao getTipoArticuloDao() {
		return new TipoArticuloSqliteDao();
	}

	@Override
	public ITipoUsuarioDao getTipoUsuarioDao() {
		return new TipoUsuarioSqliteDao();
	}

	@Override
	public IUsuarioDao getUsuarioDao() {
		return new UsuarioSqliteDao();
	}

}
